<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>缺陷管理>>缺陷类型确认</title>
    <link rel="stylesheet" href="../layui/layui.all.js"  media="all">
</head>
<body>

<div style="padding:10px;background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">缺陷管理>>缺陷类型确认</div>
                <div class="layui-card-body">
                    <!--数据表格-->
                    <table class="layui-table" id="defect_table" lay-filter="defect_table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--表格中操作：编辑、删除-->
<script type="text/html" id="operation1">
    <a class="layui-btn layui-btn-xs" lay-event="update_grade">确认级别</a>
</script>
<script type="text/javascript">
    $(function () {
        var defect = sessionStorage.getItem("defect");
        if(defect != null){
            defect = JSON.parse(defect);
            $("#emp_name").text(defect.emp_name);
        }else{
//            window.location.href = "/login.html";
        }
    });
</script>
<script>
    layui.use(['form','upload','laydate','layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,laydate = layui.laydate
            ,layedit = layui.layedit
            ,layer=layui.layer
            ,form = layui.form;
    layui.use('table', function() {
        var table = layui.table;
        table.render({
            elem: '#defect_table'
            , url: '/defectGrade.do'
            , toolbar: '#toolbarDemo'
            ,title:'缺陷等级'
            , totalRow: false
            , cols: [[
                {field: 'task_id', title: '任务编号', fixed: 'left',background:'gray'}
                , {field: 'line_id', title: '线路编号' }
                , {field: 'tower_id', title: '杆塔编号' }
                , {field: 'defect_name', title: '缺陷类型',}
                , {field: 'intact', title: '完好率' }
                , {field: 'defect_des', title: '缺陷描述'}
                , {field: 'find_time', title: '发现时间', templet : "<div>{{layui.util.toDateString(d.find_time, 'yyyy-MM-dd')}}</div>"}
                , {field: 'user_name', title: '发现人员'}
                , {fixed: 'right', title: '操作', toolbar: '#operation1',width: 80,align:'center',templet:function(row){
                    }},
            ]]
            , page: {
                limits: [5, 10, 15, 20]
            }
        });
        table.on('tool(defect_table)', function(obj) {
            if (obj.event === 'update_grade') {
                var data = obj.data;
                console.log(data);
                var index=layer.open({
                    type: 2,
                    title: ['确认缺陷级别', 'font-size:13px;background-color: #269ce9;color:white;text-algin:center'],
                    shade: [0.7, 'rgba(37,31,36,0.79)'],
                    area: ['63%', '60%'],
                    content: 'pages/sure_grade.html',
                    success:function(layero,index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        body.find("#task_id").val(data.task_id);
                        body.find("#line_id").val(data.line_id);
                        body.find("#tower_id").val(data.tower_id);
                        body.find("#defect_name").val(data.defect_name);
                        body.find("#intact").val(data.intact);
                        body.find("#defect_des").val(data.defect_des);
                        body.find("#find_time").val(data.find_time);
                        body.find("#user_name").val(data.user_name);
                        body.find("#defect_grade_name").val(data.defect_grade_name);
                    },end:function () {
                        //执行重载
                        table.reload('defect_table', {
                            where: {
                                key: {
                                    time: new Date()

                                }
                            }
                        }, 'data');
                        layer.close(index);
                    }
                });
        }
        });
    });
    });
</script>
</body>
</html>